package pers.qianyu.module.db.sync;

import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import pers.qianyu.LambLiteApplication;
import pers.qianyu.module.image.dao.ImageDao;
import pers.qianyu.module.image.dao.ImageLabelDao;
import pers.qianyu.module.image.dao.LabelDao;

/**
 * 分离出label表之后，同步数据
 *
 * @author mizzle rain
 * @date 2021-04-22 15:14
 */
@SpringBootTest(classes = LambLiteApplication.class)
@RunWith(SpringRunner.class)
public class SyncLambLabel {
    @Autowired
    private ImageDao imageDao;
    @Autowired
    private ImageLabelDao imageLabelDao;
    @Autowired
    private LabelDao labelDao;

    /*@Test
    public void execute() {
        List<ImagePO> imagePOS = imageDao.selectList(new QueryWrapper<>());
        for (ImagePO imagePO : imagePOS) {
            String label = imagePO.getLabel();
            Long id = imagePO.getId();
            Set<String> set = Arrays.stream(label.split(","))
                    .filter(StrUtil::isNotBlank)
                    .collect(Collectors.toSet());
            for (String la : set) {
                LabelPO labelPO = new LabelPO();
                labelPO.setName(la);
                LabelPO one = labelDao.selectOne(new QueryWrapper<>(labelPO));
                if (one == null) {
                    labelDao.insert(labelPO);
                } else {
                    labelPO = one;
                }
                ImageLabelPO imageLabelPO = new ImageLabelPO();
                imageLabelPO.setImageId(id);
                imageLabelPO.setLabelId(labelPO.getId());
                if (imageLabelDao.selectCount(new QueryWrapper<>(imageLabelPO)) == 0) {
                    imageLabelDao.insert(imageLabelPO);
                }
            }
        }
    }*/
}
